package com.danceforyou.common.dao;

import com.danceforyou.common.vo.SqlColumnVO;
import com.danceforyou.common.vo.SqlTableVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface GeneratorDAO {
    /**
     * 获取表列表
     * @return List<SqlTableVO>
     */
//    @Select("SELECT TABLE_NAME AS tableName,  TABLE_COMMENT AS tableComment, CREATE_TIME AS createTime, UPDATE_TIME AS updateTime " +
//            "FROM information_schema.TABLES " +
//            "WHERE TABLE_SCHEMA = (SELECT DATABASE()) " +
//            "ORDER BY TABLE_NAME")
    List<SqlTableVO> listTables();

    /**
     * 根据表名获取主键字段
     * @param tableName 表名
     * @return SqlColumnVO
     */
//    @Select("SELECT TABLE_NAME AS tableName, COLUMN_NAME AS columnName, COLUMN_COMMENT AS columnComment, DATA_TYPE AS dataType " +
//            "FROM information_schema.COLUMNS " +
//            "WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND COLUMN_KEY = 'PRI' AND TABLE_NAME = #{tableName} " +
//            "ORDER BY ORDINAL_POSITION " +
//            "LIMIT 1")
    SqlColumnVO getPriColumnsByTableName(@Param("tableName") String tableName);

    /**
     * 根据表名获取非主键字段列表
     * @param tableName 表名
     * @return List<SqlColumnVO>
     */
//    @Select("SELECT TABLE_NAME AS tableName, COLUMN_NAME AS columnName, COLUMN_COMMENT AS columnComment, DATA_TYPE AS dataType " +
//            "FROM information_schema.COLUMNS " +
//            "WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND COLUMN_KEY != 'PRI' AND TABLE_NAME = #{tableName} " +
//            "ORDER BY ORDINAL_POSITION")
    List<SqlColumnVO> listColumnsByTableName(@Param("tableName") String tableName);
}
